/**
 * JAVACC DEMO 1.0
 */
package com.apache.client;

import com.apache.api.vo.ResultEntity;
import com.apache.method.ThreadPool;

import java.util.Map;

/**
 * description:  客户端直接写日志
 *
 */
public class LogClient {

    private static LogClient instance = new LogClient();

    private ThreadPool pool;

    private LogClient() {
    }

    public static LogClient getInstance() {
        if (null == instance) {
            instance = new LogClient();
        }
        return instance;
    }

    /**
     * description:  为用户登录/ 退出提供
     *
     * @param params 参数   modelEname：模型Ename
     * 说明：登录（key:logOperationType = login;key:logIp = 实际IP；key:log_userEname = 操作用户）
     * 退出（key:logOperationType = logout;key:logIp = 实际IP；key:log_userEname = 操作用户）
     * @return
     */
    public ResultEntity execute(Map<String, Object> params) {
        return UctProtoclClient.getInstance()
        .doAuditService("auditService", "logOperationSave", params);
    }

    /**
     * description:  为用户登录/ 退出提供
     *
     * @param params 参数   modelEname：模型Ename
     * 说明：登录（key:logOperationType = login;key:logIp = 实际IP；key:log_userEname = 操作用户）
     * 退出（key:logOperationType = logout;key:logIp = 实际IP；key:log_userEname = 操作用户）
     * @return
     */
    public void doInvoke(Map<String, Object> params) {
        params.put("log_returnValue", "true");
        LoggerClientRunnable runnable = new LoggerClientRunnable(null, params);
        synchronized (instance) {
            if (null == pool) {
                pool = ThreadPool.newFixedThreadPool(3);
            }
            pool.execute(runnable);
        }
    }
}
